package com.kidback.bbloc259.ui.home;

import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;

import com.kidback.bbloc259.app.KidApplication;
import com.kidback.bbloc259.base.lang.Delay;
import com.kidback.bbloc259.base.lang.Runnable0;
import com.kidback.bbloc259.databinding.AddFriendDialogBinding;
import com.kidback.bbloc259.util.StringUtils;
import com.kidback.bbloc259.util.TipUtils;
import com.mylhyl.circledialog.BaseCircleDialog;
import com.mylhyl.circledialog.CircleDialog;
import com.mylhyl.circledialog.CircleViewHolder;
import com.mylhyl.circledialog.view.listener.OnCreateBodyViewListener;

import java.lang.ref.WeakReference;

public class AddFriendDialog {

    public static WeakReference<BaseCircleDialog> dialogRef;
    private BaseCircleDialog dialog;
    private AddFriendDialogBinding binding;

    public void show() {

        binding = AddFriendDialogBinding.inflate(LayoutInflater.from(KidApplication.getInstance()), null, false);

        binding.btnSearch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String phone = binding.edtPhone.getText().toString();

                if (StringUtils.length(phone) != 11) {
                    TipUtils.showMsgFixed(KidApplication.getCompactActivity(), "手机号格式不正确");
                    return;
                }

                requestNet(phone);
            }
        });

        dialog = new CircleDialog.Builder()
                .setWidth(0.8f)
                .setBodyView(binding.getRoot(), new OnCreateBodyViewListener() {
                    @Override
                    public void onCreateBodyView(CircleViewHolder viewHolder) {

                    }
                })
                .setGravity(Gravity.CENTER) // 位置，默认居中
                .setCanceledOnTouchOutside(true) // 触摸外部关闭，默认true
                .setCancelable(true) // 返回键关闭，默认true
                .setRadius(15) // 圆角半径
                .show(KidApplication.getCompactActivity().getSupportFragmentManager());

        dialogRef = new WeakReference<>(dialog);
    }

    private void requestNet(String phone) {

        TipUtils.showLoadingFixDialog(KidApplication.getCompactActivity(), "正在加载中");

        Delay.delay(1000, new Runnable0() {
            @Override
            public void run() {
                TipUtils.hideLoadingFixDialog();

                TipUtils.showMsgFixed(KidApplication.getCompactActivity(), "手机号不存在");
            }
        });

    }

}
